<?php

/*
 * This class is used for as Model for Admin table 
 */

class Model_Admin extends Model_Base {

    protected $_name = 'tbl_admin';
    protected $_primaryKey = 'adm_id';

    /**
     * Function to fetch admin and login details for managing session with given Log-In ID.
     *
     * @param  array|$dataArray
     * @return null|Zend_Db_Table_Row_Abstract
     */
    public function getAdminAuthData($dataArray = Array()) {
        $select = $this->select()
                ->from(array('lgn' => 'tbl_login'))
                ->setIntegrityCheck(false)
                ->join(array('adm' => 'tbl_admin'), "lgn.lgn_id = adm.lgn_id")
                ->where("adm.lgn_id = '" . $dataArray['lgn_id'] . "'")
                ->where("lgn.lgn_id = '" . $dataArray['lgn_id'] . "'");
        $data = parent::fetchRow($select);
        $object = new stdClass();
        $object->usr_id = $data->adm_id;
        $object->adm_id = $data->adm_id;
        $object->adm_companyname = $data->adm_companyname;
        $object->lgn_id = $data->lgn_id;
        $object->lgn_email = $data->lgn_email;
        $object->lgn_password = $data->lgn_password;
        $object->lgn_type = $data->lgn_type;
        $object->name = $data->adm_firstname ." ". $data->adm_lastname;
        $object->role = "ADMIN";
        $object->lgn_created = $data->lgn_created;
        $object->lgn_modified = $data->lgn_modified;
        $object->lgn_active = $data->lgn_active;
        $object->adm_firstname = $data->adm_firstname;
        $object->adm_lastname = $data->adm_lastname;
        return $object;
    }
    
    
    /**
     * Fetch an individual entry
     *
     * @param  int|string $id
     * @return null|Zend_Db_Table_Row_Abstract
     */
    public function fetchEntryById($id) {
        $select = $this->select()->where('adm_id = ?', $id);
        // see reasoning in fetchEntries() as to why we return only an array
        $data = $this->fetchRow($select);
        if (!empty($data)) {
            return $data->toArray();
        } else {
            return array();
        }
    }
    

}
